package com.yjx.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yjx.vo.Parking;
import com.yjx.service.ParkingService;
import com.yjx.mapper.ParkingMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
* @author 10657
* @description 针对表【parking】的数据库操作Service实现
* @createDate 2023-05-10 22:20:00
*/
@Service
public class ParkingServiceImpl extends ServiceImpl<ParkingMapper, Parking>
    implements ParkingService{
    @Resource
    private ParkingMapper parkingMapper;
    @Override
    public PageInfo<Parking> queryParkAll(Integer page, Integer limit, Parking parking) {
        PageHelper.startPage(page,limit);
        List<Parking> list = parkingMapper.queryParkAll(parking);
        PageInfo<Parking> pageInfo= new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean deleteByIds(Integer[] ids) {
        int len = ids.length;
        int count=baseMapper.deleteBatchIds(Arrays.asList(ids));
        if(len==count){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean addParking(Parking parking) {

        Parking parkingQuery=new Parking();
        parkingQuery.setNumbers(parking.getNumbers());
        List<Parking> parkingList=parkingMapper.queryParkAll(parkingQuery);
       if(parkingList.size()>0){
        return false;
       }else {
          return parkingMapper.insert(parking)==1;
       }
    }

    @Override
    public boolean updateParkingById(Parking parking, String oldParkingNumber) {
        Parking parkingQuery=new Parking();
        parkingQuery.setNumbers(parking.getNumbers());
        List<Parking> parkingList=parkingMapper.queryParkAll(parkingQuery);


        if(parkingList.size()>0&&!parking.getNumbers().equals(oldParkingNumber)){
            return false;
        }else {
            boolean flag = parkingMapper.updateById(parking)>0;
            return flag;
        }
    }
}




